#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/signal.h>
#define SA_SHIRQ 0x04000000
/*
 * 定义全局变量; 
 *
 */
static int irq;
static char *interface;

module_param(interface,charp,0644);
module_param(irq,int,0644);
/*定义中断函数; 
 */
static irqreturn_t myinterrupt(int irq, void *dev_id, struct pt_regs *regs)
{
	static int mycount = 0;
	if (mycount < 5) {
		printk("Interrupt!\n");
		mycount++;
	}
	return IRQ_NONE;
}
/*
	模块的初始化; lkp_init(); 
	 */

static int __init lkp_init(void)
{
	printk("hello,world, begin my modules\n"); 
	if(request_irq(irq, &myinterrupt,IRQF_SHARED,interface,&irq)){
		printk(KERN_ERR "myirqtest: cannot register IRQ %d\n", irq);
		return -EIO;
	}
	printk("%s Request on IRQ %d succeeded\n",interface,irq);
	return 0;
}


/*
	 模块的退出和清理; 
	 */

static void __exit lkp_exit(void)
{
	printk("Unloading my module\n"); 
	free_irq(irq,&irq); 
	printk("Freeing IRQ %d\n",irq); 
}

module_init(lkp_init); 
module_exit(lkp_exit); 

/*
	模块的代码许可; 
	 */
MODULE_LICENSE("GPL"); 
//执行选项; 
//sudo insmod test.ko irq=2 interface=myirq

